package com.qidian.zl.paper.dao;

import com.qidian.zl.paper.pojo.Selector;

import javax.net.ssl.SSLContext;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class SelectorDAOImpl extends BaseDAO implements SelectorDAO {


    @Override
    public List<Selector> queryFieldId(Long fieldId) {
        Connection con=null;
        PreparedStatement pst=null;
        ResultSet rs=null;
        List<Selector> selectors=new ArrayList<>();
        String sql="select * from selector where field_id=?";
        try {
            con=getCon();
            pst=con.prepareStatement(sql);
            pst.setLong(1,fieldId);
            rs= pst.executeQuery();
            while (rs.next()){
                Selector selector=new Selector();
                selector.setSelectorId(rs.getLong("selector_id"));
                selector.setSelectorText(rs.getString("selector_text"));
                selector.setFiledId(fieldId);
                selectors.add(selector);
            }
        }catch (Exception e){
            e.printStackTrace();
            throw new RuntimeException(e);
        }finally {
            closeAll(rs,pst,con);
        }
        return selectors;
    }
}
